{set:
	$seo_data=array();
	$site_config=new Config('site_config');
	$seo_data['title']=$name."_".$site_config->name;
	$seo_data['keywords']=$keywords;
	$seo_data['description']=$description;
	seo::set($seo_data);
}
{js:artTemplate}
{js:cookie}
{set:$shareInstance = new Share();$shareInstance->show();}
<link rel="stylesheet" type="text/css" href="{theme:javascript/jquery.jqzoom/css/jquery.jqzoom.css}" />
<script type="text/javascript" src="{theme:javascript/jquery.jqzoom/js/jquery.jqzoom-core-pack.js}"></script>

<link rel="stylesheet" type="text/css" href="{theme:javascript/jquery.bxSlider/jquery.bxslider.css}" />
<script type="text/javascript" src="{theme:javascript/jquery.bxSlider/jquery.bxSlider.min.js}"></script>

<div class="position"><span>您当前的位置：</span><a href="{url:}"> 首页</a> » {if:isset($category['id'])}<a href="{url:/site/pro_list/cat/$category[id]}">{$category['name']}</a> » {/if}{$name}</div>
<div class="wrapper clearfix">
	<div class="summary">
		<h2>{$name}</h2>

		<!--货品ID，当为商品时值为空-->
		<input type='hidden' id='product_id' alt='货品ID' value='' />

		<!--基本信息区域-->
		<ul>
			<li>
				<span class="f_r light_gray">商品编号：<label id="data_goodsNo">{echo:$goods_no?$goods_no:$id}</label></span>
				{if:isset($brand)}品牌：{$brand}{/if}
			</li>

			<!--抢购-->
			{if:$promo == 'time'}
				{if:isset($promotion)}
				<!--抢购正常-->
				<li class="current">
					<span class="bold red2">抢购价：</span><b class="price red2"><span class="f30">￥</span>{$promotion['award_value']}</b>
					{query:name=promotion fields=award_value,end_time,user_group where=type eq 1 and `condition` eq $id and NOW() between start_time and end_time}
					{set:$free_time = ITime::getDiffSec($item['end_time']);}
					<span class="time" id="promotiona">还剩 <i class="bold red2" id='cd_hour_promotiona'>{echo:floor($free_time/3600);}</i>小时<i class="bold red2" id='cd_minute_promotiona'>{echo:floor(($free_time%3600)/60);}</i>分<i class="bold red2" id='cd_second_promotiona'>{echo:$free_time%60;}</i>秒结束</span>
					{/query}
				</li>
				<li>
					销售价：<span class="price light_gray"><s class="f30">￥<label id="data_sellPrice">{$sell_price}</label></s></span>
					立省：￥{echo:abs($sell_price-$promotion['award_value'])}
				</li>
				{else:}
				<!--抢购过期-->
				<li><span class="f30"><img src="{skin:images/front/grab_expir.png}" style="float:right;" name="timeover" /></span></li>
				<li>销售价：<b class="price red2"><span class="f30">{if:$minSellPrice != $maxSellPrice}￥{$minSellPrice} - ￥{$maxSellPrice}{else:}￥{$sell_price}{/if}</span></b></li>
				{/if}
			{/if}

			<!--团购-->
			{if:$promo == 'groupon'}
				{if:isset($regiment)}
				<!--团购正常-->
				<li class="current">
					<span class="bold red2">团购价：</span><b class="price red2"><span class="f30">￥</span>{$regiment['regiment_price']}</b>
					{query:name=regiment fields=id as rid,regiment_price,end_time,start_time where= goods_id eq $id and  NOW() between start_time and end_time}
					{set:$free_time = ITime::getDiffSec($item['end_time']);}
					<span class="time" id="promotionb">还剩 <i class="bold red2" id='cd_hour_promotionb'>{echo:floor($free_time/3600);}</i>小时<i class="bold red2" id='cd_minute_promotionb'>{echo:floor(($free_time%3600)/60);}</i>分<i class="bold red2" id='cd_second_promotionb'>{echo:$free_time%60;}</i>秒结束</span>
					{query:name=regiment_user_relation fields=count(*) as totalNum where=regiment_id eq $item[rid] item = $value}
					<span class="bold red2">已参加团购{$value['totalNum']}人</span>
					{/query}
					{/query}
				</li>
				<li>
					销售价：<span class="price light_gray"><s class="f30">￥<label id="data_sellPrice">{$sell_price}</label></s></span>
					立省：￥{echo:abs($sell_price-$regiment['regiment_price'])}
				</li>
				{else:}
				<!--团购过期-->
				<li><span class="f30"><img src="{skin:images/front/group_expir.png}" style="float:right;" name="timeover" /></span></li>
				<li>销售价：<b class="price red2"><span class="f30">{if:$minSellPrice != $maxSellPrice}￥{$minSellPrice} - ￥{$maxSellPrice}{else:}￥{$sell_price}{/if}</span></b></li>
				{/if}
			{/if}

			<!--普通正常-->
			{if:$promo == ''}
			<!--商品价格-->
			<li id='priceLi'></li>
			{/if}

			<li>
				市场价：<s id="data_marketPrice">{if:$minMarketPrice != $maxMarketPrice}￥{$minMarketPrice} - ￥{$maxMarketPrice}{else:}￥{$market_price}{/if}</s>
			</li>

			<li>
				库存：现货<span>(<label id="data_storeNums">{$store_nums}</label>)</span>
				<a class="favorite" onclick="favorite_add(this);" href="javascript:void(0)">收藏此商品</a>
			</li>

			<li>顾客评分：<span class="grade"><i style="width:{echo:$comment_num?(14*$comment_point/$comment_num):0}px;"></i></span>(已有{$comment_num}人评价)</li>

			{if:$point > 0}
			<li>送积分：单件送{$point}分</li>
			{/if}

			<li class="relative" style="z-index:2">至
				<a class="sel_area blue" href="javascript:;">所在地区</a>：
				<span id="deliveInfo"></span>
				<div class="area_box" style="display:none;">
					<ul>
						<li><a data-code="1" href="#J_PostageTableCont"><strong>全部</strong></a></li>
						{query:name=areas where=parent_id eq 0}
						<li><a href="javascript:delivery('{$item['area_id']}','{$item['area_name']}')">{$item['area_name']}</a></li>
						{/query}
					</ul>
				</div>
			</li>
		</ul>

		<!--配送方式的模板-->
		<script type='text/html' id='deliveInfoTemplate'>
			<%if(if_delivery == 0){%>
			<%=name%>：<b class="orange"><%=price%></b>（<%=description%>）
			&nbsp;&nbsp;
			<%}else{%>
			<%=name%>：<b class="orange">该地区无法送达</b>
			&nbsp;&nbsp;
			<%}%>
		</script>

		<!--商品价格模板-->
		<script type='text/html' id='priceTemplate'>
		<%if(group_price){%>
		<li id='priceLi'>
			会员价：<b class="price red2"><span class="f30" id="real_price"><%=group_price%></span></b> &nbsp;&nbsp;&nbsp;
			销售价：<s><%if(minSellPrice != maxSellPrice){%>￥<%=minSellPrice%> - ￥<%=maxSellPrice%><%}else{%>￥<%=sell_price%><%}%></s>
		</li>
		<%}else{%>
		<li id='priceLi'>销售价：<b class="price red2"><span class="f30" id="real_price"><%if(minSellPrice != maxSellPrice){%>￥<%=minSellPrice%> - ￥<%=maxSellPrice%><%}else{%>￥<%=sell_price%><%}%></span></b></li>
		<%}%>
		</script>

		<!--购买区域-->
		<div class="current">
		{if:$store_nums <= 0}
			该商品已售完，不能购买，您可以看看其它商品！(<a href="{url:/simple/arrival/goods_id/$id}" class="orange">到货通知</a>)
		{else:}
			{if:$spec_array}
			{set:$specArray = JSON::decode($spec_array);}
			{foreach:items=$specArray}
			<dl class="m_10 clearfix" name="specCols">
				<dt>{$item['name']}：</dt>
				<dd class="w_45" style="margin-left:67px;" id="specList{$item['id']}">
					{set:$specVal=explode(',',trim($item['value'],','))}
					{foreach:items=$specVal item=$spec_value}
					{if:$item['type'] == 1}
					<div class="item w_27"><a href="javascript:void(0);" onclick="sele_spec(this);" value='{"id":"{$item['id']}","type":"{$item['type']}","value":"{$spec_value}","name":"{$item['name']}"}' >{$spec_value}<span></span></a></div>
					{else:}
					<div class="item"><a href="javascript:void(0);" onclick="sele_spec(this);" value='{"id":"{$item['id']}","type":"{$item['type']}","value":"{$spec_value}","name":"{$item['name']}"}' ><img src="{webroot:$spec_value}" width='30px' height='30px' /><span></span></a></div>
					{/if}
					{/foreach}
				</dd>
			</dl>
			{/foreach}
			{/if}

			<dl class="m_10 clearfix">
				<dt>购买数量：</dt>
				<dd>
					<input class="gray_t f_l" type="text" id="buyNums" onblur="checkBuyNums();" value="1" maxlength="5" />
					<div class="resize">
						<a class="add" href="javascript:modified(1);"></a>
						<a class="reduce" href="javascript:modified(-1);"></a>
					</div>
				</dd>
			</dl>

			{if:isset($spec_array) && $spec_array}
			<p class="m_10">已选择：<span class="orange bold" id="specSelected"></span></p>

			<!--货品规格模板-->
			<script type='text/html' id='selectedSpecTemplate'>
				<%if(type == 1){%>
					<span id="selectedSpan<%=id%>">“<%=value%>”</span>
				<%}else{%>
					<span id="selectedSpan<%=id%>"><img class="img_border" src="{webroot:<%=value%>}" width="30px" height="30px" /></span>
				<%}%>
			</script>
			{/if}

			<input class="submit_buy" type="button" id="buyNowButton" onclick="buy_now();" value="立即购买" />

			{if:$promo==''}
			<div class="shop_cart" style="z-index:1">
				<input class="submit_join" type="button" id="joinCarButton" onclick="joinCart();" value="加入购物车" />

				<div class="shopping" id="product_myCart" style='display:none'>
					<dl class="cart_stats">
						<dt class="gray f14 bold">
							<a class="close_2 f_r" href="javascript:closeCartDiv();" title="关闭">关闭</a>
							<img src="{skin:images/front/right_s.gif}" width="24" height="24" alt="" />成功加入购物车
						</dt>
						<dd class="gray">目前选购商品共<b class="orange" name='mycart_count'></b>件<span>合计：<b name='mycart_sum'></b></span></dd>
						<dd><a class="btn_blue bold" href="{url:/simple/cart}">进入购物车</a><a class="btn_blue bold" href="javascript:void(0)" onclick="closeCartDiv();">继续购物>></a></dd>
					</dl>
				</div>
			</div>
			{/if}
		{/if}
		</div>

	</div>

	<!--图片放大镜-->
	<div class="preview">
		<div class="pic_show" style="width:435px;height:435px;position:relative;z-index:5">
			<a class="jqzoom" href="javascript:void(0)" rel='goodsPhoto' id="bigPicBox" alt="原图">
				<img src="{skin:images/front/nopic_435_435.gif}" style="border:none;width:435px;height:435px" id="smallPicBox" alt="缩略图" />
			</a>
		</div>

		<div class="m_10 bx_wrap">
			<div class="bx_container">
				<ul id="thumblist" class="pic_thumb m_10">
					{foreach:items=$photo}
					{set:$bigImg=IUrl::creatUrl().$item['img'];$smallImg=Thumb::get($item['img'],435,435);}
					<li>
						<a href='javascript:void(0);' rel="{gallery:'goodsPhoto',smallimage:'{$smallImg}',largeimage:'{$bigImg}'}">
							<img src='{$smallImg}' width="60px" height="60px" />
						</a>
					</li>
					{/foreach}
				</ul>
			</div>
		</div>
	</div>
</div>

<div class="t_l">
	{if:isset($photo) && $photo}
	<a class="zoom blue" href="{url:/site/pic_show/id/$id}">点击看大图</a>
	{/if}
</div>

<div class="wrapper clearfix container_2">

	<!--左边栏-->
	<div class="sidebar f_l">
		{if:isset($buyer_id) && $buyer_id}
		<div class="box m_10">
			<div class="title">购买本商品的用户还购买过</div>
			<div class="content">
				<ul class="ranklist">
					{query:name=order_goods as og join= join order as o on og.order_id eq o.id left join goods as lg on lg.id eq og.goods_id AND lg.is_del eq 0 fields= DISTINCT lg.id,lg.sell_price as price,lg.small_img,lg.name where= o.user_id in ($buyer_id) AND lg.id is not null order = o.completion_time desc limit=5}
					<li class="current">
						<a href="{url:/site/products/id/$item[id]}"><img width="58px" height="58px" src="{webroot:$item[small_img]}"></a>
						<a title="{$item['name']}" class="p_name" href="{url:/site/products/id/$item[id]}">{$item['name']}</a>
						<b>￥{$item['price']}</b>
					</li>
					{/query}
				</ul>
			</div>
		</div>
		{/if}

		<div class="box m_10">
			<div class="title">热卖商品</div>
			<div class="content">
				<ul class="ranklist">
				{query:name=commend_goods as cg join= left join goods as lg on lg.id eq cg.goods_id fields=lg.name,lg.sell_price,lg.small_img,lg.id where=commend_id eq 3 AND lg.is_del eq 0 AND lg.id is not null order=lg.sort asc,lg.id desc limit=5}
					<li class="current">
						<a href="{url:/site/products/id/$item[id]}"><img width="58px" height="58px" alt="{$item['name']}" src="{webroot:$item[small_img]}" /></a>
						<a title="{$item['name']}" class="p_name" href="{url:/site/products/id/$item[id]}">{$item['name']}</a>
						<b>￥{$item['sell_price']}</b>
					</li>
				{/query}
				</ul>
			</div>
		</div>
	</div>

	<!--滑动面tab标签-->
	<div class="main f_r" style="overflow:hidden">

		<div class="uc_title">
			<label onclick="selectTab('tab_1','lab-1')" id="lab-1" name="lab-name" class="current"><span>商品详情</span></label>
			<label onclick="selectTab('tab_2','lab-2')" id="lab-2" name="lab-name"><span>顾客评价({$comment_num})</span></label>
			<label onclick="selectTab('tab_3','lab-3')" id="lab-3" name="lab-name"><span>购买记录({$buy_num})</span></label>
			<label onclick="selectTab('tab_4','lab-4')" id="lab-4" name="lab-name"><span>购买前咨询({$refer})</span></label>
			<label onclick="selectTab('tab_5','lab-5')" id="lab-5" name="lab-name"><span>网友讨论圈({$discussion})</span></label>
			<label onclick="selectTab('tab_6','lab-6')" id="lab-6" name="lab-name"><span>售后服务</span></label>
			<label onclick="selectTab('tab_7','lab-7')" id="lab-7" name="lab-name"><span>支付方式</span></label>
		</div>

		<!-- 商品详情 start -->
		<div id="tab_1" name="div_name">
			<ul class="saleinfos m_10 clearfix">
				<li>商品名称：{$name}</li>

				{if:isset($brand) && $brand}
				<li>品牌：{$brand}</li>
				{/if}

				{if:isset($weight) && $weight}
				<li>商品毛重：<label id="data_weight">{$weight}</label></li>
				{/if}

				{if:isset($unit) && $unit}
				<li>单位：{$unit}</li>
				{/if}

				{if:isset($up_time) && $up_time}
				<li>上架时间：{$up_time}</li>
				{/if}

				{if:($attribute)}
				{foreach:items=$attribute}
				<li>{$item['name']}：{$item['attribute_value']}</li>
				{/foreach}
				{/if}
			</ul>
			{if:isset($content) && $content}
			<div class="salebox">
				<strong class="saletitle block">产品描述：</strong>
				<p class="saledesc">{$content}</p>
			</div>
			{/if}
		</div>
		<!-- 商品详情 end -->

		<!-- 顾客评论 start -->
		<div class="comment_list box" id="tab_2" name="div_name" style="display:none;">
			<div class="title3">
				<span class="f_r f12 light_gray normal">
					只有购买过该商品的用户才能进行评价
					{if:isset($this->user['user_id']) && $user_id = $this->user['user_id']}
					{query:name=comment fields=id where=status eq 0 and goods_id eq $id and user_id eq $user_id limit=1}
					<a class="comm_btn" href="{url:/site/comments/id/$item[id]}">我要评论</a>
					{/query}
					{/if}
				</span>
				<img src="{skin:images/front/comm.gif}" width="16px" height="16px" />商品评论<span class="f12 normal">（已有<b class="red2">{$comment_num}</b>条）</span>
			</div>

			<div id='commentBox'></div>

			<!--评论JS模板-->
			<script type='text/html' id='commentRowTemplate'>
			<div class="item">
				<div class="user">
					<div class="ico">
						<a href="javascript:void(0)">
							<img src="{webroot:<%=head_ico%>}" width="70px" height="70px" onerror="this.src='{skin:images/front/user_ico.gif}'" />
						</a>
					</div>
					<span class="blue"><%=username%></span>
				</div>
				<dl class="desc">
					<%var widthPoint = 14 * point;%>
					<p class="clearfix">
						<b>评分：</b>
						<span class="grade"><i style="width:<%=widthPoint%>px"></i></span>
						<span class="light_gray"><%=time%></span><label></label>
					</p>
					<hr />
					<p><b>评价：</b><span class="gray"><%=contents%></span></p>
				</dl>
				<div class="corner b"></div>
			</div>
			<hr />
			</script>
		</div>
		<!-- 顾客评论 end -->

		<!-- 购买记录 start -->
		<div class="box" id="tab_3" name="div_name" style="display:none;">
			<div class="title3">
				<img src="{skin:images/front/cart.gif}" width="16" height="16" alt="" />
				购买记录<span class="f12 normal">（已有<b class="red2">{$buy_num}</b>购买）</span>
			</div>

			<table width="100%" class="list_table m_10 mt_10">
				<col width="150" />
				<col width="120" />
				<col width="120" />
				<col width="150" />
				<col />
				<thead class="thead">
					<tr>
						<th>购买人</th>
						<th>出价</th>
						<th>数量</th>
						<th>购买时间</th>
						<th>状态</th>
					</tr>
				</thead>
			</table>

			<table width="100%" class="list_table m_10">
				<col width="150" />
				<col width="120" />
				<col width="120" />
				<col width="150" />
				<col />
				<tbody class="dashed" id="historyBox"></tbody>

				<!--购买历史js模板-->
				<script type='text/html' id='historyRowTemplate'>
				<tr>
					<td><%=username%></td>
					<td><%=goods_price%></td>
					<td class="bold orange"><%=goods_nums%></td>
					<td class="light_gray"><%=completion_time%></td>
					<td class="bold blue">成交</td>
				</tr>
				</script>
			</table>
		</div>
		<!-- 购买记录 end -->

		<!-- 购买前咨询 start -->
		<div class="comment_list box" id="tab_4" name="div_name" style="display:none;">
			<div class="title3">
				<span class="f_r f12 normal"><a class="comm_btn" href="{url:/site/consult/id/$id}">我要咨询</a></span>
				<img src="{skin:images/front/cart.gif}" width="16" height="16" />购买前咨询<span class="f12 normal">（共<b class="red2">{$refer}</b>记录）</span>
			</div>

			<div id='referBox'></div>

			<!--购买咨询JS模板-->
			<script type='text/html' id='referRowTemplate'>
			<div class="item">
				<div class="user">
					<div class="ico"><img src="{webroot:<%=head_ico%>}" width="70px" height="70px" onerror="this.src='{skin:images/front/user_ico.gif}'" /></div>
					<span class="blue"><%=username%></span>
					<p class="gray"><%=rtime%></p>
				</div>
				<dl class="desc gray">
					<p>
						<img src="{skin:images/front/ask.gif}" width="16px" height="17px" />
						<b>咨询内容：</b><span class="f_r"><%=time%></span>
					</p>
					<p class="indent"><%=question%></p>
					<hr />
					<%if(answer){%>
					<p class="bg_gray"><img src="{skin:images/front/answer.gif}" width="16px" height="17px" />
					<b class="orange">{echo:$siteConfig->name}回复：</b><span class="f_r"><%=reply_time%></span></p>
					<p class="indent bg_gray"><%=answer%></p>
					<%}%>
				</dl>
				<div class="corner b"></div>
				<div class="corner tl"></div>
			</div>
			<hr />
			</script>
		</div>
		<!-- 购买前咨询 end -->

		<!-- 网友讨论圈 start -->
		<div class="box" id="tab_5" name="div_name" style="display:none;">
			<div class="title3">
				<span class="f_r f12 normal"><a class="comm_btn" href="javascript:sendDiscuss();">发表话题</a></span>
				<img src="{skin:images/front/discuss.gif}" width="18px" height="19px" />
				网友讨论圈<span class="f12 normal">（共<b class="red2">{$discussion}</b>记录）</span>
			</div>
			<div class="wrap_box no_wrap">
				<!--讨论内容列表-->
				<table width="100%" class="list_table">
					<col />
					<col width="150">
					<tbody id='discussBox'></tbody>
				</table>

				<!--讨论JS模板-->
				<script type='text/html' id='discussRowTemplate'>
				<tr>
					<td class="t_l discussion_td" style="border:none;">
						<span class="blue"><%=username%></span>
					</td>
					<td style="border:none;" class="t_r gray discussion_td"><%=time%></td>
				</tr>
				<tr><td class="t_l" colspan="2" style="padding:0 7px 0 13px;"><%=contents%></td></tr>
				</script>

				<!--讨论内容输入框-->
				<table class="form_table" style="display:none;" id="discussTable">
					<col width="80px">
					<col />

					<tbody>
						<tr>
							<th>讨论内容：</th>
							<td valign="top"><textarea id="discussContent" pattern="required" alt="请填写内容"></textarea></td>
						</tr>
						<tr>
							<th>验证码：</th>
							<td><input type='text' class='gray_s' name='captcha' pattern='^\w{5}$' alt='填写下面图片所示的字符' /><label>填写下面图片所示的字符</label></td>
						</tr>
						<tr class="low">
							<th></th>
							<td><img src='{url:/site/getCaptcha}' id='captchaImg' /><span class="light_gray">看不清？<a class="link" href="javascript:changeCaptcha('{url:/site/getCaptcha}');">换一张</a></span></td>
						</tr>
						<tr>
							<td></td>
							<td><label class="btn"><input type="submit" value="发表" onclick="sendDiscussData();" /></label></td>
						</tr>
					</tbody>
				</table>
			</div>
		</div>
		<!-- 网友讨论圈 end -->

		<!-- 售后服务 start -->
		<div class="box" id="tab_6" name="div_name" style="display:none;">
			<div class="title3"><img src="{skin:images/front/tel.gif}" width="20px" height="19px" />售后服务</div>
			<div class="cont_s gray">
				{query:name=help fields=content where=id eq 52}
					{echo:$item['content']}
				{/query}
			</div>
		</div>
		<!-- 售后服务 end -->

		<!-- 支付方式 start -->
		<div class="box" id="tab_7" name="div_name" style="display:none;">
			<div class="title3"><img src="{skin:images/front/card.gif}" width="23px" height="18px" />支付方式</div>
			<div class="cont_pay">
				{query:name=help fields=content where=id eq 53}
					{echo:$item['content']}
				{/query}
			</div>
		</div>
		<!-- 支付方式 end -->
	</div>
</div>

<script type="text/javascript">
$(function(){

//图片初始化
var goodsSmallPic = "{skin:images/front/nopic_435_435.gif}";
var goodsBigPic   = "{skin:images/front/nopic_435_435.gif}";

//存在图片数据时候
{if:isset($photo) && $photo}
goodsSmallPic = "{echo:Thumb::get($photo[0]['img'],435,435)}";
goodsBigPic   = "{webroot:}{$photo[0]['img']}";
{/if}

//初始化商品轮换图
var bxObj = $('#thumblist').bxSlider({
	infiniteLoop: false,
	hideControlOnEnd: true,
	pager:false,
	minSlides: 5,
	maxSlides: 5,
	slideWidth: 72,
	slideMargin: 15,
	controls:true,
	onSliderLoad:function(currentIndex){
		//设置图片
		$('#smallPicBox').attr('src',goodsSmallPic);
		$('#bigPicBox').attr('href',goodsBigPic);

		//开启放大镜
		$('.jqzoom').jqzoom({
			title:false,
			lens:true,
			preloadText:'加载中...',
			zoomWidth:300,
			zoomHeight:300,
			xOffset:15,
		    zoomType: 'standard',
		    preloadImages: false
		});
	}
});

//如果抢购或团购过期则不许立即购买
{if:$promo!='' && !isset($promotion) && !isset($regiment)}
	closeBuy();
{/if}

//如果当前是团购
{if:isset($regiment)}
	{set:$reg_id = IFilter::act(IReq::get('active_id'),'int');}

	//团购检查,1,人数已满 2,已经参加过
	{if:Regiment::isFull($reg_id) || (isset($this->user['user_id']) && Regiment::hasJoined($reg_id,$this->user['user_id'])) || (ICookie::get("regiment_".$reg_id) && Regiment::hasJoined($reg_id,ICookie::get("regiment_".$reg_id)))}
		closeBuy();
	{/if}
{/if}

//开启倒计时功能
var cd_timer = new countdown();

//限时抢购倒计时
{if:isset($promotion)}
cd_timer.add('promotiona');
{/if}

//团购倒计时
{if:isset($regiment)}
cd_timer.add('promotionb');
{/if}

//城市地域选择按钮事件
$('.sel_area').hover(
	function(){
		$('.area_box').show();
	},function(){
		$('.area_box').hide();
	}
);
$('.area_box').hover(
	function(){
		$('.area_box').show();
	},function(){
		$('.area_box').hide();
	}
);

//获取地址的ip地址
getAddress();

//生成商品价格
var priceHtml = template.render('priceTemplate',{"group_price":"{$group_price}","minSellPrice":"{$minSellPrice}","maxSellPrice":"{$maxSellPrice}","sell_price":"{$sell_price}"});
$('#priceLi').replaceWith(priceHtml);

});

//禁止购买
function closeBuy()
{
	if($('#buyNowButton').length > 0)
	{
		$('#buyNowButton').attr('disabled','disabled');
		$('#buyNowButton').addClass('disabled');
	}

	if($('#joinCarButton').length > 0)
	{
		$('#joinCarButton').attr('disabled','disabled');
		$('#joinCarButton').addClass('disabled');
	}
}

//开放购买
function openBuy()
{
	if($('#buyNowButton').length > 0)
	{
		$('#buyNowButton').removeAttr('disabled');
		$('#buyNowButton').removeClass('disabled');
	}

	if($('#joinCarButton').length > 0)
	{
		$('#joinCarButton').removeAttr('disabled');
		$('#joinCarButton').removeClass('disabled');
	}
}

//加载根据地域获取城市
function getAddress()
{
	//根据IP查询所在地
	var ipAddress = $.cookie('ipAddress');
	if(ipAddress)
	{
		searchDelivery(ipAddress);
	}
	else
	{
		$.getScript('http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js',function(){
			ipAddress = remote_ip_info['province'];
			$.cookie('ipAddress',ipAddress);
			searchDelivery(ipAddress);
		});
	}
}

//发表讨论
function sendDiscuss()
{
	var userId = "{$this->user['user_id']}";
	if(userId)
	{
		$('#discussTable').show('normal');
		$('#discussContent').focus();
	}
	else
	{
		alert('请登陆后再发表讨论!');
	}
}

/**
 * 根据省份获取运费信息
 * @param province 省份名称
 */
function searchDelivery(province)
{
	var url = '{url:/block/searchPrivice/random/@random@}';
	url = url.replace("@random@",Math.random);

	$.getJSON(url,{'province':province},function(json)
	{
		if(json.flag == 'success')
		{
			delivery(json.area_id,province);
		}
	});
}

//选择当前Tab
function selectTab(curr_div,curr_lab)
{
	//如果有ajax获取数据的tab标签
	switch(curr_div)
	{
		case "tab_2":
		{
			comment_ajax();
		}
		break;

		case "tab_3":
		{
			history_ajax();
		}
		break;

		case "tab_4":
		{
			refer_ajax();
		}
		break;

		case "tab_5":
		{
			discuss_ajax();
		}
		break;
	}

	$("div[name='div_name']").hide();
	$("#"+curr_div).show();

	$("label[name='lab-name']").removeClass();
	$("#"+curr_lab).addClass('current');
}

/**
 * 计算运费
 * @param provinceId
 * @param provinceName
 */
function delivery(provinceId,provinceName)
{
	$('.sel_area').text(provinceName);

	var weight  = '{$weight}';
	var buyNums = $('#buyNums').val();

	//通过省份id查询出配送方式，并且传送总重量计算出运费,然后显示配送方式
	var totalWeight = parseInt(weight) * parseInt(buyNums);
	var url = '{url:/block/order_delivery}';

	$.getJSON(url,{'province':provinceId,'total_weight':totalWeight,'random':Math.random},function(json)
	{
		//清空配送信息
		$('#deliveInfo').empty();

		for(var item in json)
		{
			var deliveRowHtml = template.render('deliveInfoTemplate',json[item]);
			$('#deliveInfo').append(deliveRowHtml);
		}
	});
}

/**
 * 获取评论数据
 * @page 分页数
 */
function comment_ajax(page)
{
	if(!page && $.trim($('#commentBox').text()))
	{
		return;
	}
	page = page ? page : 1;
	var url = '{url:/site/comment_ajax/page/@page@/goods_id/$id}';
	url = url.replace("@page@",page);
	$.getJSON(url,function(json)
	{
		//清空评论数据
		$('#commentBox').empty();

		for(var item in json.data)
		{
			var commentHtml = template.render('commentRowTemplate',json.data[item]);
			$('#commentBox').append(commentHtml);
		}
		$('#commentBox').append(json.pageHtml);
	});
}

/**
 * 获取购买记录数据
 * @page 分页数
 */
function history_ajax(page)
{
	if(!page && $.trim($('#historyBox').text()))
	{
		return;
	}
	page = page ? page : 1;
	var url = '{url:/site/history_ajax/page/@page@/goods_id/$id}';
	url = url.replace("@page@",page);
	$.getJSON(url,function(json)
	{
		//清空购买历史记录
		$('#historyBox').empty();
		$('#historyBox').parent().parent().find('.pages_bar').remove();

		for(var item in json.data)
		{
			var historyHtml = template.render('historyRowTemplate',json.data[item]);
			$('#historyBox').append(historyHtml);
		}
		$('#historyBox').parent().after(json.pageHtml);
	});
}

/**
 * 获取购买记录数据
 * @page 分页数
 */
function refer_ajax(page)
{
	if(!page && $.trim($('#referBox').text()))
	{
		return;
	}
	page = page ? page : 1;
	var url = '{url:/site/refer_ajax/page/@page@/goods_id/$id}';
	url = url.replace("@page@",page);
	$.getJSON(url,function(json)
	{
		//清空评论数据
		$('#referBox').empty();

		for(var item in json.data)
		{
			var commentHtml = template.render('referRowTemplate',json.data[item]);
			$('#referBox').append(commentHtml);
		}
		$('#referBox').append(json.pageHtml);
	});
}

/**
 * 获取购买记录数据
 * @page 分页数
 */
function discuss_ajax(page)
{
	if(!page && $.trim($('#discussBox').text()))
	{
		return;
	}
	page = page ? page : 1;
	var url = '{url:/site/discuss_ajax/page/@page@/goods_id/$id}';
	url = url.replace("@page@",page);
	$.getJSON(url,function(json)
	{
		//清空购买历史记录
		$('#discussBox').empty();
		$('#discussBox').parent().parent().find('.pages_bar').remove();

		for(var item in json.data)
		{
			var historyHtml = template.render('discussRowTemplate',json.data[item]);
			$('#discussBox').append(historyHtml);
		}
		$('#discussBox').parent().after(json.pageHtml);
	});
}

//发布讨论数据
function sendDiscussData()
{
	var content = $('#discussContent').val();
	var captcha = $('[name="captcha"]').val();

	if($.trim(content)=='')
	{
		alert('请输入讨论内容!');
		$('#discussContent').focus();
		return false;
	}
	if($.trim(captcha)=='')
	{
		alert('请输入验证码!');
		$('[name="captcha"]').focus();
		return false;
	}

	var url = '{url:/site/discussUpdate/id/$id/captcha/@captcha@/random/@Math@}';
	url = url.replace("@captcha@",captcha).replace("@Math@",Math.random);

	$.getJSON(url,{'content':content},function(json)
	{
		if(json.isError == false)
		{
			var discussHtml = template.render('discussRowTemplate',json);
			$('#discussBox').prepend(discussHtml);

			//清除数据
			$('#discussContent').val('');
			$('[name="captcha"]').val('');
			$('#discussTable').hide('normal');
			changeCaptcha('{url:/site/getCaptcha}');
		}
		else
		{
			alert(json.message);
		}
	});
}

/**
 * 规格的选择
 * @param _self 规格本身
 */
function sele_spec(_self)
{
	var specObj = $.parseJSON($(_self).attr('value'));

	//清除同规格下已选数据
	$('#selectedSpan'+specObj.id).remove();

	//已经为选中状态时
	if($(_self).attr('class') == 'current')
	{
		$(_self).removeClass('current');
		$('#selectedSpan'+specObj.id).remove();
	}
	else
	{
		//清除同行中其余规格选中状态
		$('#specList'+specObj.id).find('a.current').removeClass('current');

		$(_self).addClass('current');
		var newSpecHtml = template.render('selectedSpecTemplate',specObj);
		$('#specSelected').append(newSpecHtml);
	}

	//检查规格是否选择符合标准
	if(checkSpecSelected())
	{
		//整理规格值
		var specArray = [];
		$('[name="specCols"]').each(function(){
			specArray.push($(this).find('a.current').attr('value'));
		});
		var specJSON = '['+specArray.join(",")+']';

		//获取货品数据并进行渲染
		$.getJSON('{url:/site/getProduct}',{"goods_id":"{$id}","specJSON":specJSON,"random":Math.random},function(json){
			if(json.flag == 'success')
			{
				//普通商品购买方式(非团购，抢购等),商品价格渲染
				if($('#priceLi').length > 0)
				{
					var priceHtml = template.render('priceTemplate',json.data);
					$('#priceLi').replaceWith(priceHtml);
				}
				//非普通商品购买方式，商品价格渲染
				else if($('#data_sellPrice').length > 0)
				{
					$('#data_sellPrice').text(json.data.sell_price);
				}

				//普通货品数据渲染
				$('#data_goodsNo').text(json.data.products_no);
				$('#data_storeNums').text(json.data.store_nums);
				$('#data_marketPrice').text("￥"+json.data.market_price);
				$('#data_weight').text(json.data.weight);
				$('#product_id').val(json.data.id);

				//库存监测
				checkStoreNums();
			}
			else
			{
				alert(json.message);
				closeBuy();
			}
		});
	}
}

/**
 * 监测库存操作
 */
function checkStoreNums()
{
	var storeNums = parseInt($.trim($('#data_storeNums').text()));
	if(storeNums > 0)
	{
		openBuy();
	}
	else
	{
		closeBuy();
	}
}

/**
 * 检查规格选择是否符合标准
 * @return boolen
 */
function checkSpecSelected()
{
	if($('[name="specCols"]').length === $('[name="specCols"] .current').length)
	{
		return true;
	}
	return false;
}

//检查购买数量是否合法
function checkBuyNums()
{
	//购买数量小于0
	var buyNums = parseInt($.trim($('#buyNums').val()));
	if(buyNums <= 0)
	{
		$('#buyNums').val(1);
		return;
	}

	//购买数量大于库存
	var storeNums = parseInt($.trim($('#data_storeNums').text()));
	if(buyNums >= storeNums)
	{
		$('#buyNums').val(storeNums);
		return;
	}
}

/**
 * 购物车数量的加减
 * @param code 增加或者减少购买的商品数量
 */
function modified(code)
{
	var buyNums = parseInt($.trim($('#buyNums').val()));
	switch(code)
	{
		case 1:
		{
			buyNums++;
		}
		break;

		case -1:
		{
			buyNums--;
		}
		break;
	}

	$('#buyNums').val(buyNums);
	checkBuyNums();
}

//商品加入购物车
function joinCart()
{
	if(!checkSpecSelected())
	{
		tips('请先选择商品的规格');
		return;
	}

	var buyNums   = parseInt($.trim($('#buyNums').val()));
	var price     = parseFloat($.trim($('#real_price').text()));
	var productId = $('#product_id').val();
	var type      = productId ? 'product' : 'goods';
	var goods_id  = (type == 'product') ? productId : {$id};

	$.getJSON('{url:/simple/joinCart}',{"goods_id":goods_id,"type":type,"goods_num":buyNums,"random":Math.random},function(content){
		if(content.isError == false)
		{
			//获取购物车信息
			$.getJSON('{url:/simple/showCart}',{"mode":"json"},function(json)
			{
				$('[name="mycart_count"]').text(json.count);
				$('[name="mycart_sum"]').text(json.sum);

				//展示购物车清单
				$('#product_myCart').show();

				//暂闭加入购物车按钮
				$('#joinCarButton').attr('disabled','disabled');
			});
		}
		else
		{
			alert(content.message);
		}
	});
}

//添加收藏夹
function favorite_add(obj)
{
	{if:isset($this->user['user_id'])}
		$.getJSON('{url:/simple/favorite_add}',{'goods_id':{$id},'random':Math.random},function(content)
		{
			if(content.isError == false)
			{
				$(obj).text(content.message);
			}
			else
			{
				alert(content.message);
			}
		});
	{else:}
		window.location.href="{url:/simple/login/?callback=/site/products/id/$id}";
	{/if}
}

//立即购买按钮
function buy_now()
{
	//对规格的检查
	if(!checkSpecSelected())
	{
		tips('请选择商品的规格');
		return;
	}

	//设置必要参数
	var buyNums  = parseInt($.trim($('#buyNums').val()));
	var id = {$id};
	var type = 'goods';

	if($('#product_id').val())
	{
		id = $('#product_id').val();
		type = 'product';
	}

	{if:$promo}
	//有促销活动（团购，抢购）
	var url = '{url:/simple/cart2/id/@id@/num/@buyNums@/type/@type@/promo/$promo/active_id/$active_id}';
	url = url.replace('@id@',id).replace('@buyNums@',buyNums).replace('@type@',type);
	{else:}
	//普通购买
	var url = '{url:/simple/cart2/id/@id@/num/@buyNums@/type/@type@}';
	url = url.replace('@id@',id).replace('@buyNums@',buyNums).replace('@type@',type);
	{/if}

	//页面跳转
	window.location.href = url;
}
</script>
